import * as echarts from "echarts";
const scaleData = [
  {
    name: "很满意",
    value: 99,
  },
  {
    name: "一般满意",
    value: 10,
  },
  {
    name: "不满意",
    value: 5,
  },
];
export const getProposalSatisfactionOption = () => {
  return {
    title: {
      top: 15,
      left: 10,
      textStyle: {
        fontSize: 16,
        color: "#fff",
      },
      text: "提宰办理满意度统计",
    },
    grid: {
      left: "5%",
      right: "2%",
      bottom: "3%",
      top: "20%",
      containLabel: true,
    },
    tooltip: {
      show: false,
    },
    toolbox: {
      show: false,
    },
    series: seriesObj,
  };
};

const rich = {
  white: {
    color: "#05D5FF",
    align: "center",
    padding: [10, 0],
  },
};
const placeHolderStyle = {
  label: {
    show: false,
  },
  labelLine: {
    show: false,
  },
  color: "rgba(0, 0, 0, 0)",
  borderColor: "rgba(0, 0, 0, 0)",
  borderWidth: 0,
};
let data = [];
for (let i = 0; i < scaleData.length; i++) {
  data.push(
    {
      value: scaleData[i].value,
      name: scaleData[i].name,
      itemStyle: {
        borderWidth: 10,
        shadowBlur: 30,
        borderColor: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
          {
            offset: 0,
            color: "#7777eb",
          },
          {
            offset: 1,
            color: "#70ffac",
          },
        ]),
        shadowColor: "rgba(142, 152, 241, 0.6)",
      },
    },
    {
      value: 4,
      name: "",
      itemStyle: placeHolderStyle,
    }
  );
}

const seriesObj = [
  {
    name: "",
    type: "pie",
    clockWise: false,
    radius: [92, 90],
    hoverAnimation: false,

    label: {
      show: true,
      position: "outside",
      color: "#4B7EFE",
      formatter: function (params: any) {
        let percent = 0 as number | string;
        let total = 0;
        for (let i = 0; i < scaleData.length; i++) {
          total += scaleData[i].value;
        }
        percent = ((params.value / total) * 100).toFixed(0);
        if (params.name !== "") {
          return (
            params.name +
            "\n{white|" +
            "占比" +
            percent +
            "% }" +
            "{white|" +
            "共" +
            params.value +
            "条}"
          );
        } else {
          return "";
        }
      },
      rich: rich,
    },
    labelLine: {
      show: false,
    },
    data: data,
  },
];
